package com.mmlc.businessutils;

import android.view.View;
import android.widget.RadioButton;

import com.androidnetframe.httputil.BaseRequestFilterLayer;
import com.androidnetframe.responsejavabean.RequestError;
import com.mmlc.meimei.lichengkongjian.been.OrderButtonBean;
import com.mmlc.meimei.lichengkongjian.dialog.CustomDialog;
import com.mmlc.network.filter.ConfirmOrderRequestFilter;
import com.mmlc.network.filter.WantRefundRequestFilter;
import com.mmlc.utils.ToastUtils;

/**
 * Created by Administrator on 2016/8/16 0016.
 * 申请退款
 */
public class ConfirmOrderRequest {


    private CustomDialog dialog;
    OrderListUtils orderListUtils;
    OrderButtonBean buttonBean;
    public ConfirmOrderRequest(OrderListUtils orderListUtils){
       this.orderListUtils = orderListUtils;
       this.buttonBean = orderListUtils.buttonBean;
    }

    public void confirmOrder(){
        ConfirmOrderRequestFilter filter = new ConfirmOrderRequestFilter(buttonBean.activity);
        filter.requestBean.order_id =buttonBean.orderId;
        filter.offerErrorParams(buttonBean.rootView);
        filter.isTransparence = true;
        filter.sendRequest(new BaseRequestFilterLayer.AccessResultFromFilter<String>() {

            @Override
            public void onSuccess(String result) {
                ToastUtils.showToast("确认收货成功");
                RadioButton rb = (RadioButton) buttonBean.buttonView;
                rb.setText("已收货");
            }

            @Override
            public void onFailed(View errorLayout, RequestError serverError, int failedType) {
                ToastUtils.showToast(serverError.mess);
            }
        });
    }

    public View showEdit(int layoutId) {
        if (dialog == null) {
            dialog = new CustomDialog(buttonBean.activity);
        }
        dialog.setView(layoutId);
        dialog.show();
        return dialog.getContentView();
    }
    private void refundRequest(String orderId, String reason) {
        WantRefundRequestFilter filter = new WantRefundRequestFilter(buttonBean.activity);
        filter.requestBean.order_id =orderId;
        filter.requestBean.reason =reason;
        filter.sendRequest(new BaseRequestFilterLayer.AccessResultFromFilter<String>() {

            @Override
            public void onSuccess(String result) {
                ToastUtils.showToast("退款申请成功");
                if(dialog.dialog.isShowing()){
                    dialog.dialog.dismiss();
                }
            }

            @Override
            public void onFailed(View errorLayout, RequestError serverError, int failedType) {
                ToastUtils.showToast("退款申请失败");
            }
        });
    }
}
